package com.mt.roll.common.controller;

import com.mt.roll.common.service.CommonService;
import com.mt.roll.common.vo.SysFileVo;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *
 * </P>
 *
 * @author FanYi
 * @date 2020/7/6
 * @since 1.0
 */
@Api(value = "公共模块", tags = "公共模块")
@RestController
@RequestMapping(CommonConstant.API_MODULE_COMMON)
@Slf4j
@RequiredArgsConstructor
public class CommonController extends BaseController {
    private final CommonService commonService;


    @PostMapping(value = "downloadFile")
    @ApiOperation(value = "获取附件下载地址", notes = "获取附件下载地址")
    public R<SysFileVo> downloadFile(@Validated @RequestBody IdParam idParam) {
        return successful(commonService.downloadFile(idParam.getId()));
    }

    @GetMapping(value = "downLoadFileUrl")
    @ApiOperation(value = "文件的预览", notes = "文件的预览")
    public R<Object> downloadFile(@Validated IdParam idParam, HttpServletResponse response) {
        return commonService.downLoadFileUrl(idParam, response);
    }


}
